package daizuo;


import daizuo.bean.Cust;
import daizuo.utils.Readerinfo;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author cyt
 * @create 2020-07-21 11:58
 */
public class Discount {

    public static void DiscountMenu() {
        System.out.println("------------------");
        System.out.println("1、幸运大放送");
        System.out.println("2、幸运抽奖");
        System.out.println("3、生日问候");
        System.out.println("------------------");
        selectDiscountMenu();
    }


    private static void three() {
        System.out.println("输入今天的日期； ");
        String data = new Scanner(System.in).nextLine();
        ArrayList<String> list = Readerinfo.read("cust");
        Cust cust = new Cust();

        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            String[] split = s.split(",");
            if (split[5].equals(data)) {
                System.out.println("今天过生日的会员是； " + split[1]);
                break;
            }
        }

        System.out.println("输入 n  返回上一级");

        String isReturn = new Scanner(System.in).nextLine();
        if (isReturn.equals("n")) {
            try {
                Menu.mainMenu();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            three();
        }


    }

    private static void two() {
        System.out.println("是否开始 y/n");

        String isContinue = new Scanner(System.in).nextLine();
        if ("y".equals(isContinue)) {
            System.out.println("幸运客户获奖； MP3");
            DiscountMenu();
        } else {
            DiscountMenu();
        }

    }


    public static void one() {
        String ans = null;
        ArrayList<String> list = Readerinfo.read("cust");
        Cust cust = new Cust();

        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            String[] split = s.split(",");
            for (int j = i + 1; j < list.size(); j++) {
                String sj = list.get(j);
                String[] splitJ = sj.split(",");
                if (Integer.valueOf(split[5]) > Integer.valueOf(splitJ[5])) {
                    ans = split[1];
                }
            }
        }

        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            String[] split = s.split(",");
            if (split[1].equals(ans)) {
                cust.setCustNo(split[1]);
                cust.setCustBirth(split[3]);
                cust.setCustScore(split[5]);
                System.out.println(cust.toString());
            }
        }
        System.out.println("获奖 100 元");

        System.out.println("n 返回上一级");

        String isContinue = new Scanner(System.in).nextLine();
        if ("n".equals(isContinue)) {
            try {
                Menu.mainMenu();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            one();
        }
    }

    public static void selectDiscountMenu() {
        int uA1 = 1;
        int uA2 = 2;
        int uA3 = 3;
        System.out.println("请选择，输入数字：   输入 0 返回上一级");
        int select = new Scanner(System.in).nextInt();
        if (select == uA1) {
            one();
        } else if (select == uA2) {
            two();
        } else if (select == uA3) {
            three();
        } else if (select == 0) {
            try {
                Menu.mainMenu();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
